// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const head = require('./head/head');

cc.Class({
    extends: cc.Component,

    properties: {
        bgSetSdr: cc.Slider,    //背景音乐
        mp3SetSdr: cc.Slider,   //音效
    },

    onLoad() {
        //初始化
        head.main(this);
        //层节点
        this.layerGame = null;
        //监听
        //添加子弹
        ICPC.on('addBullet', this.onAddBullet.bind(this));
        //子弹资源加载完毕
        ICPC.on('loadBulletResEnd', this.onLoadBulletResEnd.bind(this));
        //飞机资源完毕
        ICPC.on('loadFlyResEnd', this.onLoadFlyResEnd.bind(this));
        //敌机资源
        ICPC.on('loadEnemyResEnd', this.onLoadEnemyResEnd.bind(this));
        //特效资源
        ICPC.on('loadEffectResEnd', this.onLoadEffectResEnd.bind(this));
        //所有资源加载完毕
        ICPC.on('loadAllResEnd', this.onLoadAllEnd.bind(this));
        //加载资源
        ICPC.bulletManager.loadBulletRes();
        ICPC.flyManager.loadFlyRes();
        ICPC.enemyManager.loadEnemyRes();
        ICPC.effectManager.loadEffectRes();
        ICPC.soundManager.loadSoundTexture();
    },

    onLoadAllEnd(data) {
        console.log('==所有资源加载完毕==');
        ICPC.gameDataManager.onLoadAllEnd(data);
    },

    onLoadBulletResEnd(data) {
        console.log('子弹加载完毕');
        //
    },

    onLoadFlyResEnd(data) {
        console.log('飞机加载完毕');
        //
    },

    onLoadEnemyResEnd(data) {
        console.log('敌机资源加载完毕');
    },

    onLoadEffectResEnd(data) {
        console.log('特效资源加载完毕');
    },

    onAddBullet(data) {
        const id = data;
    },

    onBtnStart() {
        ICPC.gameDataManager.startGame();
    },

    onBtnHelp() {
        ICPC.gameDataManager.onHelpClick();
    },

    onBtnRank() {
        ICPC.gameDataManager.onRankClick();
    },

    onBtnContinue() {
        ICPC.gameDataManager.continueGame();
    },

    onBtnContinuePlay(){
        ICPC.gameDataManager.onContinue();
    },

    onBtnTitle() {
        ICPC.gameDataManager.OnCheatPlus();
    },

    onBtnSet() {
        ICPC.gameDataManager.onSetClick();
        this.bgSetSdr.progress = ICPC.soundManager.getBGMVoice();
        this.mp3SetSdr.progress = ICPC.soundManager.getEFFECTVoice();
        //
        let lbNum = this.bgSetSdr.node.getChildByName('lbNum').getComponent(cc.Label);
        lbNum.string = Math.floor(this.bgSetSdr.progress * 100) + '%';
        let lb2Num = this.mp3SetSdr.node.getChildByName('lbNum').getComponent(cc.Label);
        lb2Num.string = Math.floor(this.mp3SetSdr.progress * 100) + '%';
    },

    onSliderBGM() {
        let bgmVoice = this.bgSetSdr.progress;
        ICPC.soundManager.setBGMVoice(bgmVoice);
        let lbNum = this.bgSetSdr.node.getChildByName('lbNum').getComponent(cc.Label);
        lbNum.string = Math.floor(bgmVoice * 100) + '%';
    },

    onSliderEffect(event, custom) {
        console.log(event._touchHandle);
        let effectVoice = this.mp3SetSdr.progress;
        ICPC.soundManager.setEFFECTVoice(effectVoice);
        let lbNum = this.mp3SetSdr.node.getChildByName('lbNum').getComponent(cc.Label);
        lbNum.string = Math.floor(effectVoice * 100) + '%';
        ICPC.soundManager.playBt();
    },

    start() {

    },

    // update (dt) {},
});
